package com.shamar.blog.enums;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @author runquanchen
 * @version 1.0
 * @date 2020-01-19 20:16
 * @project channel
 */
public enum ClearStatusEnum {

    INIT(0, "初始化"),

    SUCCESS(1, "成功"),

    FAIL(2, "失败"),

    PROCESS(3, "处理中"),

    UNKNOWN(4, "未知"),

    RERTY(5,"可重试");


    private int status;
    private String desc;

    ClearStatusEnum(int code, String desc) {
        this.status = code;
        this.desc = desc;
    }

    public int getStatus() {
        return status;
    }

    public String getDesc() {
        return desc;
    }

    public static Boolean isFinish(Integer status) {
        return status == SUCCESS.getStatus() || status == FAIL.getStatus();
    }

    public static Boolean isEnd(Integer status) {
        return status == SUCCESS.getStatus() || status == FAIL.getStatus() || status == RERTY.getStatus();
    }

    public static Boolean isNotFinish(Integer status) {
        return !isFinish(status);
    }

    public static ClearStatusEnum getByCode(int code) {
        for (ClearStatusEnum anEnum : ClearStatusEnum.values()) {
            if (anEnum.getStatus() == code) {
                return anEnum;
            }
        }
        return ClearStatusEnum.UNKNOWN;
    }

    public static ClearStatusEnum toPayByCode(int code) {

        if (RERTY.getStatus() == code) {
            return PROCESS;
        }
        for (ClearStatusEnum anEnum : ClearStatusEnum.values()) {
            if (anEnum.getStatus() == code) {
                return anEnum;
            }
        }
        return ClearStatusEnum.UNKNOWN;
    }

    public static Map<String, String> toMap() {
        Map<String, String> map = new LinkedHashMap<>();
        for (ClearStatusEnum value : values()) {
            map.put(String.valueOf(value.status), value.desc);
        }
        return map;
    }

}
